<?php
/**
  * tframe
  *
  *
  * @copyright Copyright (c) 2012 - 2014, huxiaomin
  * @author huxiaomin    2012-6-9  
  * @since		Version 1.0
  *
  */

class ATableApp{
    private $dao;
	
	function __construct(){
		$this->dao = new TTable();
	}
	
	//显示所有的表
    function listTable(){
    	new TTable('duser');
        $dao = $this->dao;
        $sql = "show table status";
        $rows = $dao->GetPlan($sql);
        return array('tables' => $rows);
    }

    //显示一个表的详细信息
    function descTable($request){
    	$table = mysql_real_escape_string($request['table']);
    	if (empty($table)){
    	   return '';
    	}
        $dao = $this->dao;
        $sql = "show full fields from {$table}";
        //$sql = "desc {$table}";
        $rows = $dao->GetPlan($sql);
        $data['data']= array('tables' => $rows);
        return TTpl::startOb('admin/ATable.descTable.html',$data,$request);
    }
    
    /**
     * 显示table memcache缓存的信息
     * @param $request
     */
    function getTableMemcache($request){
    	$table_name = trim($request['table']);
        $TTableMemcache = new TTableMemcache();
        $data['data'] = $TTableMemcache->getTable($table_name);
        
        return TTpl::startOb('admin/Atable.memcache.html',$data,$request);
    }
    
    function setMemcache($request){
    	$table_cache = array(
                       'name'=>trim($request['name']), //表名
                       'memcache_open'=>intval($request['memcache_open']), //是否开缓存
                       'memcache_time'=>intval($request['memcache_time']), //缓存时间  0表示永不失效
                       'refresh'=>trim($request['refresh']),   //刷新时间 dateTime
                   );
    	$TTableMemcache = new TTableMemcache();
    	$TTableMemcache->addConfig($table_cache);
    	
    	return goutJson(1,'','success ',$request);
    }
    
    
}